Skip to content

Conversation

DanRyanIrish
Copy link
Member

@DanRyanIrish DanRyanIrish commented Aug 15, 2025

To Do

@DanRyanIrish DanRyanIrish added this to the 2.4.0 milestone Aug 15, 2025
Copy link
Member

@wtbarnes wtbarnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to wrap my head around what's happening here and I don't see anything obviously problematic (though I don't know much about NDData either). My one suggestion would be adding a test that constructs an NDData from a dask array (I think this is possible??) and then apply a these operations (at least add and mul) to that object and ensure that the laziness is preserved in these new codepaths.

@DanRyanIrish
Copy link
Member Author

@wtbarnes: Do these tests satisfy your comment?

@DanRyanIrish
Copy link
Member Author

@Cadair @wtbarnes: Docs on Arithmetic operations are now included in this PR. Please let me know if you have comments. If not, I'd appreciate an approval :)

@DanRyanIrish
Copy link
Member Author

DanRyanIrish commented Oct 5, 2025

@Cadair it looks like NDData(cube, wcs=None) doesn't actually set the wcs to None! https://github.com/sunpy/ndcube/actions/runs/18262220518/job/51991663154?pr=880

@Cadair
Copy link
Member

Cadair commented Oct 6, 2025

Oh, of course it doesn’t. Well balls.

I'm not really sure what the best option is in that case then.

@DanRyanIrish
Copy link
Member Author

Oh, of course it doesn’t. Well balls.

I'm not really sure what the best option is in that case then.

Dare a say it? NDCube.drop_coords() -> NDData?

@nabobalis
Copy link
Member

Oh, of course it doesn’t. Well balls.
I'm not really sure what the best option is in that case then.

Dare a say it? NDCube.drop_coords() -> NDData?

Do it

@DanRyanIrish DanRyanIrish marked this pull request as draft October 7, 2025 10:14
A motivating use case for this method is in enabling arithmetic operations between
`~ndcube.NDCube` instances by removing coordinate-awareness. See the section of the
ndcube documentation on
'Enabling Arithmetic Operations between NDCubes with NDCube.to_nddata'.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wtbarnes @Cadair : Is there a way of referencing this section here as a link (and with the correct section title) as can be done in the docs themselves?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Enabling Arithmetic Operations between NDCubes with NDCube.to_nddata'.
:ref:`arithmetic`.

Should do it.

@DanRyanIrish DanRyanIrish marked this pull request as ready for review October 9, 2025 12:17
@@ -0,0 +1 @@
Enable subtraction and division of `~ndcube.NDCube` by an `~astropy.nddata.NDData` instance, including uncertainty, mask and unit support.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Enable subtraction and division of `~ndcube.NDCube` by an `~astropy.nddata.NDData` instance, including uncertainty, mask and unit support.
Enable subtraction and division of `~ndcube.NDCube` by an `~astropy.nddata.NDData` instance (without a WCS), including uncertainty, mask and unit support.

Comment on lines +221 to +223
>>> import warnings
>>> with warnings.catch_warnings():
... warnings.simplefilter("ignore") # Catching warnings not needed but keeps docs cleaner.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan, it makes the warnings surprising for people following along at home. What warnings are we squashing?

Arithmetic Operations Between NDCubes
=====================================

Why Arithmetic Operations between NDCubes Are Not Supported Directly (but Are Indirectly)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sArCaStIC Capitalisation

Suggested change
Why Arithmetic Operations between NDCubes Are Not Supported Directly (but Are Indirectly)
Why Arithmetic Operations between NDCubes Are Not Supported Directly (but are indirectly)

where addition, subtraction, multiplication and division are all enabled by the ``+``, ``-``, ``*``, and ``/`` operators, respectively.

Note that `~ndcube.NDCube` attributes not supported by the constructor of the output type employed by `ndcube.NDCube.to_nddata` are dropped by the conversion.
Therefore, since `ndcube.NDCube.to_nddata` converts to `~astropy.nddata.NDData` by default, there was no need in the above example to explicitly set `~ndcube.NDCube.extra_coords` and `~ndcube.NDCube.global_coords` to ``None``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you anyway?

Comment on lines +308 to +314
Note that the output type of `ndcube.NDCube.to_nddata` can be controlled via the ``nddata_type`` kwarg.
For example:

>>> from astropy.nddata import NDDataRef
>>> nddataref2 = cube2.to_nddata(wcs=None, nddata_type=NDDataRef)
>>> print(type(nddataref2) is NDDataRef)
True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels irrelevant to the narrative here and just documentation of to_nddata, and therefore in the wrong place?

Comment on lines +319 to +327
`ndcube.NDCube.to_nddata` is not limited to changing/removing the WCS.
The value of any input supported by the ``nddata_type``'s constructor can be altered by setting a kwarg for that input, e.g.:

.. code-block:: python
>>> nddata_ones = cube2.to_nddata(data=np.ones(cube2.data.shape))
>>> nddata_ones.data
array([[1., 1., 1.],
[1., 1., 1.]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this section, feels like the wrong place for this example? It's not relevant to arithmetic operations?

A motivating use case for this method is in enabling arithmetic operations between
`~ndcube.NDCube` instances by removing coordinate-awareness. See the section of the
ndcube documentation on
'Enabling Arithmetic Operations between NDCubes with NDCube.to_nddata'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Enabling Arithmetic Operations between NDCubes with NDCube.to_nddata'.
:ref:`arithmetic`.

Should do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants